package au.edu.swin.videoshop.persistence;

import java.io.Serializable;

import javax.persistence.Column;
import javax.persistence.Entity;
import javax.persistence.GeneratedValue;
import javax.persistence.GenerationType;
import javax.persistence.Id;
import javax.persistence.NamedQueries;
import javax.persistence.NamedQuery;
import javax.persistence.Table;
import javax.persistence.Transient;

import au.edu.swin.videoshop.bean.Address;
import au.edu.swin.videoshop.bean.AddressState;

@Entity
@NamedQueries({
	@NamedQuery (
			name="findAllStores", 
			query="SELECT s FROM StoreEntity s WHERE s.deleted = FALSE"
	)
})
@Table(name="STORE")
public class StoreEntity implements Serializable{
	private Long mStoreId;
	private String mStoreName;
	private Address mAddress;
	
	//Attribute to mark the entity as deleted
	private boolean mDeleted;
	private String mDeleteInfo;
	
	public StoreEntity() {
		mDeleted = false;
	}
	
	/**
	 * @return the storeId
	 */
	@Id
	@GeneratedValue (strategy=GenerationType.AUTO)
	@Column(name="STORE_ID")
	public Long getStoreId() {
		return mStoreId;
	}
	
	/**
	 * @param storeId the storeId to set
	 */
	public void setStoreId(Long storeId) {
		mStoreId = storeId;
	}

	/**
	 * @return the storeName
	 */
	@Column(name="STORE_NAME", length=50)
	public String getStoreName() {
		return mStoreName;
	}
	
	/**
	 * @param storeName the storeName to set
	 */
	public void setStoreName(String storeName) {
		mStoreName = storeName;
	}

	/**
	 * @return
	 * @see au.edu.swin.videoshop.bean.Address#getAddressLine()
	 */
	@Column(name="ADDRESS_LINE", length=200)
	public String getAddressLine() {
		return mAddress.getAddressLine();
	}

	/**
	 * @return
	 * @see au.edu.swin.videoshop.bean.Address#getPostcode()
	 */
	@Column(name="POSTCODE", length=10)
	public String getPostcode() {
		return mAddress.getPostcode();
	}

	/**
	 * @return
	 * @see au.edu.swin.videoshop.bean.Address#getState()
	 */
	@Column(name="STATE", length=10)
	public String getState() {
		return mAddress.getState().getName();
	}

	/**
	 * @return
	 * @see au.edu.swin.videoshop.bean.Address#getSuburb()
	 */
	@Column(name="SUBURB", length=200)
	public String getSuburb() {
		return mAddress.getSuburb();
	}

	/**
	 * @param addressLine1
	 * @see au.edu.swin.videoshop.bean.Address#setAddressLine(java.lang.String)
	 */
	public void setAddressLine(String addressLine) {
		if (mAddress == null) {
			mAddress = new Address();
		}
		mAddress.setAddressLine(addressLine);
	}

	/**
	 * @param postcode
	 * @see au.edu.swin.videoshop.bean.Address#setPostcode(java.lang.String)
	 */
	public void setPostcode(String postcode) {
		if (mAddress == null) {
			mAddress = new Address();
		}
		mAddress.setPostcode(postcode);
	}

	/**
	 * @param state
	 * @see au.edu.swin.videoshop.bean.Address#setState(java.lang.String)
	 */
	public void setState(String state) {
		if (mAddress == null) {
			mAddress = new Address();
		}
		mAddress.setState(AddressState.getInstance(state));
	}

	/**
	 * @param suburb
	 * @see au.edu.swin.videoshop.bean.Address#setSuburb(java.lang.String)
	 */
	public void setSuburb(String suburb) {
		if (mAddress == null) {
			mAddress = new Address();
		}
		mAddress.setSuburb(suburb);
	}

	/**
	 * @return the address
	 */
	@Transient
	public Address getAddress() {
		return mAddress;
	}

	/**
	 * @param address the address to set
	 */
	public void setAddress(Address address) {
		mAddress = address;
	}
	
	/**
	 * @return the deleted
	 */
	@Column(name="IS_DELETED")
	public boolean isDeleted() {
		return mDeleted;
	}
	
	/**
	 * @param deleted the deleted to set
	 */
	public void setDeleted(boolean deleted) {
		mDeleted = deleted;
	}
	
	/**
	 * @return the deleteInfo
	 */
	@Column(name="DELETE_INFO")
	public String getDeleteInfo() {
		return mDeleteInfo;
	}
	
	/**
	 * @param deleteInfo the deleteInfo to set
	 */
	public void setDeleteInfo(String deleteInfo) {
		mDeleteInfo = deleteInfo;
	}
}
